from rest_framework import serializers

from . import models


class CourseCategoryModelSerializers(serializers.ModelSerializer):
	class Meta:
		model = models.CourseCategory
		fields = ['id', 'name']


class TeacherModelSerializers(serializers.ModelSerializer):
	class Meta:
		model = models.Teacher
		fields = ['id', 'name', 'title', 'signature', 'brief', 'image']


class CourseModelSerializers(serializers.ModelSerializer):
	teacher = TeacherModelSerializers()

	class Meta:
		model = models.Course
		fields = ['id', 'name', 'discount_name', 'real_price', 'course_img', 'students', 'lessons', 'pub_lessons', 'price', 'teacher', 'get_lessons']


class CourseDetailModelSerializer(serializers.ModelSerializer):

	teacher = TeacherModelSerializers()

	class Meta:
		model = models.Course
	# 获取choice属性参数的值,可以直接使用get_属性名称_display
		fields = ['id', 'name', 'discount_name', 'real_price', 'course_img', 'students', 'lessons', 'mod_brief', 'teacher', 'pub_lessons', 'price', 'teacher', 'get_level_display']


class LessonModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = models.CourseLesson
        fields = ['id', 'name', 'section_link', 'duration', 'free_trail', 'lesson']


class ChapterModelSerializer(serializers.ModelSerializer):
    coursesections = LessonModelSerializer(many=True)  # 注意：一套多的时候，属性名称为related_name的值

    class Meta:
        model = models.CourseChapter
        fields = ['id', 'chapter', 'name', 'coursesections']

